﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi.Entity
{
    public class DbinitializeHelper
    {
        public static void Initlizer()
        {
            using (var db = new Admin4000Dbcontext())
            {
                db.Database.EnsureCreated();
                var tempBrand =db.Brands.Any();
                if (!tempBrand)
                {
                    var brand = new Brand()
                    {
                        BrandName = "Apple",
                        Description = "美国",
                    };
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    db.products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="Iphone X 红色",
                        ShorDesc="简介",
                        FullDesc="详情",
                        BrandId=brand.Id
                    },
                    new Product
                    {
                        ProductName="Iphone X 黑色",
                        ShorDesc="简介",
                        FullDesc="详情",
                        BrandId=brand.Id
                    }

                    });
                    db.SaveChanges();
                }
                
            }
        }
    }
}
